/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package vm.help;

import java.awt.Dimension;
import java.awt.Point;
import java.awt.event.MouseEvent;
import javax.swing.JTable;
import javax.swing.ToolTipManager;
import javax.swing.table.TableCellRenderer;
import javax.swing.table.TableModel;

/**
 *
 * @author Peer
 */
public class HelpTable extends JTable {
    
    TableCellRenderer renderer;

    public HelpTable(TableModel dm) {
        super(dm);
        renderer = new HelpTableCellRenderer();
        setIntercellSpacing(new Dimension(6,0));
        setCellSelectionEnabled(false);
        getTableHeader().setReorderingAllowed(false);
        getTableHeader().setResizingAllowed(false);
        getColumnModel().getColumn(0).setMaxWidth(getTableHeader().getDefaultRenderer().getTableCellRendererComponent(this, "Cmd", false, false, 0, 0).getPreferredSize().width+4);
        //System.out.println(getTableHeader().getDefaultRenderer().getTableCellRendererComponent(this, "Cmd", false, false, 0, 0).getClass().toString());
        ToolTipManager.sharedInstance().setDismissDelay(Integer.MAX_VALUE);
    }

    @Override
    public String getToolTipText(MouseEvent event) {
        Point P = event.getPoint();
        int column = columnAtPoint(P);
        int row = rowAtPoint(P);
        column = convertColumnIndexToModel(column);
        if(column == 1)
            return (String)getValueAt(row, column);
        else
            return super.getToolTipText(event);
        }

    @Override
    public TableCellRenderer getCellRenderer(int row, int column) {
        return renderer;
    }

}
